//
//  LXRetweetedView.m
//  微了个小博
//
//  Created by imera on 15/10/12.
//  Copyright (c) 2015年 imera. All rights reserved.
//

#import "LXRetweetedView.h"
#import "LXStatusFrame.h"
#import "LXStatus.h"
#import "LXUser.h"
#import "UIImageView+WebCache.h"
#import "LXPhotosView.h"

@interface LXRetweetedView()

/** 被转发的微博的用户的昵称 */
@property (nonatomic, weak) UILabel *retweetedNameLabel;
/** 被转发的微博的会员图标 */
@property (nonatomic, weak) UIImageView *retweetedVipImage;
/** 被转发的微博的内容(文字) */
@property (nonatomic, weak) UILabel *retweetedTextLabel;
/** 被转发的微博的单张配图 */
@property (nonatomic, weak) LXPhotosView *retweetedPhotoImage;
@end

@implementation LXRetweetedView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if(self){
        self.image = [UIImage resizeWithName:@"timeline_retweet_background" left:0.9 top:0.5];
        self.userInteractionEnabled = YES;
        
        [self setupSubViews];
    }
    return self;
}

/**
 *  初始化子控件
 */
- (void)setupSubViews
{
    /** 被转发的微博的用户的昵称 */
    UILabel *retweetedNameLabel = [[UILabel alloc]init];
    self.retweetedNameLabel = retweetedNameLabel;
    [self addSubview:retweetedNameLabel];
    
    /** 被转发的微博会员图标 */
    UIImageView *retweetedVipImage = [[UIImageView alloc]init];
    self.retweetedVipImage = retweetedVipImage;
    [self addSubview:retweetedVipImage];
    
    /** 被转发的微博的内容(文字) */
    UILabel *retweetedTextLabel = [[UILabel alloc]init];
    self.retweetedTextLabel = retweetedTextLabel;
    [self addSubview:retweetedTextLabel];
    
    /** 被转发的微博的单张配图 */
    LXPhotosView *retweetedPhotoImage = [[LXPhotosView alloc]init];
    self.retweetedPhotoImage = retweetedPhotoImage;
    [self addSubview:retweetedPhotoImage];
}

- (void)setStatusF:(LXStatusFrame *)statusF
{
    _statusF = statusF;
    
    LXStatus *retweetedStatus = statusF.status.retweeted_status;
    LXUser *retweetedUser = retweetedStatus.user;
    
    /** 被转发微博用户的昵称 */
    self.retweetedNameLabel.text = [NSString stringWithFormat:@"@%@",retweetedUser.screen_name];
    self.retweetedNameLabel.font = LXStatusNameFont;
    self.retweetedNameLabel.frame = statusF.retweetedNameF;
    
    /** 会员图标 */
    if (retweetedUser.mbtype) {
        self.retweetedVipImage.hidden = NO;
        self.retweetedVipImage.image = [UIImage imageNamed:[NSString stringWithFormat:@"common_icon_membership_level%d", retweetedUser.mbrank]];
        self.retweetedVipImage.frame = statusF.retweetedVipViewF;
        self.retweetedNameLabel.textColor = [UIColor orangeColor];
    } else {
        self.retweetedVipImage.hidden = YES;
        self.retweetedNameLabel.textColor = [UIColor blackColor];
    }
    
    /** 被转发微博微博的内容(文字) */
    self.retweetedTextLabel.text = retweetedStatus.text;
    self.retweetedTextLabel.font = LXStatusTextFont;
    self.retweetedTextLabel.numberOfLines = 0;
    self.retweetedTextLabel.frame = statusF.retweetedTextF;
    
    /** 被转发微博微博的配图 */
    if(retweetedStatus.pic_urls.count){
        self.retweetedPhotoImage.hidden = NO;
        self.retweetedPhotoImage.pic_urls = retweetedStatus.pic_urls;
        self.retweetedPhotoImage.frame = statusF.retweetedPic_urlsF;
    }else{
        self.retweetedPhotoImage.hidden = YES;
    }
}

@end
